<template>
  <div id="jump-page">
    <div class="jump-header">
      <div class="jump-header-title">
        <img :src="param.icon" width="40" />
        <p>{{ param.name }}</p>
      </div>
      <div class="spinner">
        <div class="bounce1"></div>
        <div class="bounce2"></div>
        <div class="bounce3"></div>
      </div>
    </div>
    <p v-if="tip" style="margin-top: 30px;text-align: center;">
      {{ param.maintainTip }}
    </p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      param: {},
      tip: false,
      iconShow: false
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      let sessionId = sessionStorage.getItem("jump_id");
      if (sessionId) {
        this.param = JSON.parse(sessionId);
        if (this.param.maintain !== 0) {
          this.tip = true;
        }
        if (this.param.available === 1 && this.param.maintain === 0) {
          this.handleRoute(this.param);
        }
      }
    },
    handleRoute(item) {
      let jump_param = this.modelFunctions.checkJumpType(item.pageUrl);
      console.log("ietm", jump_param);
      if (jump_param && jump_param.type) {
        if (jump_param.type === "h5") {
          window.location.replace(
            item.pageUrl +
              (item.pageUrl.indexOf("?") !== -1 ? "&" : "?") +
              "access_token=" +
              // localStorage.getItem("token")
              localStorage.getItem("token")
          );
        } else if (jump_param.type === "h5_anonymous") {
          if (item.pageUrl.indexOf("www.baidu") !== -1) {
            this.$router.replace("/building");
          } else {
            window.location.replace(item.pageUrl);
          }
        } else if (jump_param.type === "wx") {
          // this.pullApp(jump_param.params);
          this.pullApp(jump_param);
          // this.pullApp(item);
        }
      }
    },
    async pullApp(obj) {
      if (obj.url) {
        let res = this.$bridge.jsCall(
          "pullApp",
          JSON.stringify({ url: obj.params })
        );
        if (res) {
          location.href = "/inner?back=" + JSON.stringify(res);
        } else {
          this.$router.push("/code");
        }
      } else {
        this.$bridge.jsCall("pullApp", JSON.stringify(obj.params));
        this.$router.replace("/code");
      }
      // if (!obj.code) {
      //   this.$bridge.jsCall("pullApp", JSON.stringify(obj));
      //   this.$router.replace("/code");
      // } else {
      //   let res = await this.$bridge.jsCall("pullApp", JSON.stringify(obj));
      //   if (res) {
      //     location.href = "/inner?back=" + JSON.stringify(res);
      //   } else {
      //     this.$router.push("/code");
      //   }
      // }

      // let params = JSON.stringify(obj);
      // 跳转app，app拉起微信小程序--传参：code、wx_id（微信小程序原始ID）、wx_type（微信小程序版本：正式版0、开发板1、体验版2）
      // let res = await this.$bridge.jsCall("pullApp", { params });
    }
  }
};
</script>

<style lang="less" scoped>
#jump-page {
  .jump-header {
    margin-top: 50px;

    .jump-header-title {
      text-align: center;
      p {
        padding: 4px 0;
        font-size: 14px;
        color: #333;
      }
    }
    .spinner {
      text-align: center;
      /*position: absolute;*/
      /*left: 50%;*/
      /*top: 45%;*/
      /*transform: translate(-45%, -50%);*/
    }

    .spinner > div {
      width: 10px;
      height: 10px;
      background-color: #bfbfbf;

      border-radius: 100%;
      display: inline-block;
      -webkit-animation: bouncedelay 1.4s infinite ease-in-out;
      animation: bouncedelay 1.4s infinite ease-in-out;
      /* Prevent first frame from flickering when animation starts */
      -webkit-animation-fill-mode: both;
      animation-fill-mode: both;
    }

    .spinner .bounce1 {
      -webkit-animation-delay: -0.32s;
      animation-delay: -0.32s;
      background-color: #dbdbdb;
    }

    .spinner .bounce2 {
      -webkit-animation-delay: -0.16s;
      animation-delay: -0.16s;
      background-color: #cdcdcd;
    }

    @-webkit-keyframes bouncedelay {
      0%,
      80%,
      100% {
        -webkit-transform: scale(0);
      }
      40% {
        -webkit-transform: scale(1);
      }
    }

    @keyframes bouncedelay {
      0%,
      80%,
      100% {
        transform: scale(0);
        -webkit-transform: scale(0);
      }
      40% {
        transform: scale(1);
        -webkit-transform: scale(1);
      }
    }
  }
}
</style>
